package com.xunji.xunji.module.account.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.xunji.xunji.R;
import com.xunji.xunji.module.account.bean.MenuInfo;

import java.util.List;

/**
 * Created by Paul on 2017/2/2.
 */

public class MenuAdapter extends BaseAdapter{

    private List<MenuInfo> mList;
    private Context mContext;

    public MenuAdapter(List<MenuInfo> mList, Context mContext) {
        this.mList = mList;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder = null;

        if (convertView==null){
            holder = new Holder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_slide_menu,null);

            holder.imageView = (ImageView) convertView.findViewById(R.id.iv_image);
            holder.textView = (TextView) convertView.findViewById(R.id.tv_title);

            convertView.setTag(holder);
        }else {
            holder = (Holder) convertView.getTag();
        }

        holder.textView.setText(mList.get(position).getTitle());
        holder.imageView.setImageResource(mList.get(position).getResId());


        return convertView;
    }

    class Holder{

        ImageView imageView;
        TextView textView;
    }
}